package com.leftheart.utils;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.ibatis.annotations.Mapper;
import org.junit.Test;
import org.springframework.context.annotation.Configuration;

@Configuration
@Mapper
public class Utils {

    private static int month;
    private static int day;

    public long setAccounts(){
        long account=System.currentTimeMillis();
        long accounts=account%100000000;

        return accounts;
    }

    public static Long setRentalId(){
        long account1=System.currentTimeMillis();
        long accounts = account1%10000;
//        ObjectMapper objectMapper=new ObjectMapper();
//        配置json默认时间戳格式为false
//        objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false);
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd");
//        objectMapper.setDateFormat(dateFormat);
//        String string = objectMapper.writeValueAsString(date);
//        long l = Long.parseLong(string);

//        long b= Long.parseLong();
//        stringBuffer.toString();

        /*
         *
         * 社会月份 天 为两位数
         */
        if (DateUtil.thisMonth()+1<10){
            String stringMonth="0"+DateUtil.thisMonth()+1;
            month = Integer.parseInt(stringMonth);
        }else {
            month=DateUtil.thisMonth()+1;
        }
        if (DateUtil.thisDayOfMonth()<10){
            String stringDay="0"+DateUtil.thisDayOfMonth();
            day = Integer.parseInt(stringDay);
        }else {
            day = DateUtil.thisDayOfMonth();
        }
//        hutool获取到当前的年 月 日 拼接位字符串
        String dateIdString=""+DateUtil.thisYear()+month+day;

//        System.out.println(""+month+DateUtil.thisDayOfMonth());
//
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(dateIdString);
        stringBuffer.append(accounts);

        return Long.valueOf(String.valueOf(stringBuffer));
    }

    @Test
    public void test(){
        System.out.println(setRentalId());
    }
}

